#coding:utf-8
'''
Created on 2017-04-20

@author: sandy
'''

import os
import logging
from pycommon import RemoteManager


class Config(object):
    
    def __init__(self):
        self.rundir = os.path.dirname(__file__)
        self.server_ip = u"127.0.0.1"
        self.server_port = 0
        self.public_ip = u"127.0.0.1"
        self.public_port = 0
        self.center_ip = u"127.0.0.1"
        self.center_port = 8500
        
        self.max_client = 0
        self.game_type = u""

    
    def onRemoteConfig(self, cfgname, jf):
        ctype,cname = cfgname.split(u".")
        if ctype==u'server'+unicode(RemoteManager.instance.sid) and cname==u'serverconfig':
            self.loadFromJson(jf)
       
    def loadFromJson(self, cf):
        logging.debug(u'Gameserver parse serverconfig')
        self.server_ip = cf.get("server_ip")
        self.server_port = cf.get("server_port")
        self.center_ip = cf.get("center_ip")
        self.center_port = cf.get("center_port")
        self.public_ip = cf.get("public_ip")
        self.public_port = cf.get("public_port")
        self.max_client = cf.get("max_client")
        self.game_type = cf.get("game_type")
   
instance = Config()